package www.sharetime.weshare.base;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import www.sharetime.weshare.event.NetWorkEvent;

/**
 * File Description  :  fragmentActivity 管理的基类
 *
 * @author : zhanggeng
 * @version : v1.0
 *          **************修订历史*************
 * @email : zhanggengdyx@gmail.com
 * @date : 17/9/12 20:29
 */

public class BaseFragmentActivity extends FragmentActivity implements BaseInterface {


    protected LayoutInflater mInflater;

    protected Unbinder unbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setTheme(R.style.MyActivityTheme);

        onBeforeSetContentLayout();

        if (getLayoutId() != 0) {
            setContentView(getLayoutId());
        }

        if (unbinder == null) {
            unbinder = ButterKnife.bind(this);
        }

        mInflater = getLayoutInflater();

        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }

        initView(savedInstanceState);

        initData();
    }



    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onCallBack(NetWorkEvent netWorkEvent) {
        if (netWorkEvent != null && netWorkEvent.getType() == NetWorkEvent.UNAVAILABLE) {
            //TODO: toast remind
        }
    }

    protected void onBeforeSetContentLayout() {
    }

    protected int getLayoutId() {
        return 0;
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }


    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }


    @Override
    public void initView(Bundle savedInstanceState) {

    }

    @Override
    public void initData() {

    }

}
